using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework
{
    [TestClass]
    public class WhenCreatingTimeSpan
    {
        [TestMethod]
        public void ShouldReturnDayForDayTimeUnit()
        {
            double value = 1;
            TimeUnit timeUnit = TimeUnit.Day;

            TimeSpan expected = TimeSpan.FromDays(value);
            TimeSpan actual = TimeSpanHelper.Create(value, timeUnit);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ShouldReturnHourForHourTimeUnit()
        {
            double value = 2;
            TimeUnit timeUnit = TimeUnit.Hour;

            TimeSpan expected = TimeSpan.FromHours(value);
            TimeSpan actual = TimeSpanHelper.Create(value, timeUnit);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ShouldReturnMinuteForMinuteTimeUnit()
        {
            double value = 3;
            TimeUnit timeUnit = TimeUnit.Minute;

            TimeSpan expected = TimeSpan.FromMinutes(value);
            TimeSpan actual = TimeSpanHelper.Create(value, timeUnit);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ShouldReturnSecondForSecondTimeUnit()
        {
            double value = 4;
            TimeUnit timeUnit = TimeUnit.Second;

            TimeSpan expected = TimeSpan.FromSeconds(value);
            TimeSpan actual = TimeSpanHelper.Create(value, timeUnit);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ShouldThrowWhenInvalidTimeUnit()
        {
            double value = 4;
            TimeUnit timeUnit = (TimeUnit) 5;

            TimeSpanHelper.Create(value, timeUnit);
        }
    }
}